< previous page page_193 next page >

Page 193
e10a6a0a59f035e870d90cca05b85fce.gif
    ' Allocate space for the result pixels. 
    ReDim result_pixels( _ 
        LBound(input_pixels, 1) To UBound(input_pixels, 1), 
        LBound(input_pixels, 2) To UBound(input_pixels, 2)) 

    ' Set the pixel colors. Note that we 
    ' must skip the edges because some of 
    ' the kernel values would correspond 
    ' to pixels off the image. 
    For Y = bound To picOriginal.ScaleHeight - 1 - bound 
        For X = bound To picOriginal.ScaleWidth - 1 - bound 
            ' Start with no color. 
            r = 0 
            g = 0 
            b = 0 
            ' Apply the kernel values to 
            ' the nearby pixels. 
            For i = -bound To bound 
                For j = -bound To bound 
                    With input_pixels(X + i, Y + j) 
                        r = r + .rgbRed * kernel(i, j) 
                        g = g + .rgbGreen * kernel(i, j) 
                        b = b + .rgbBlue * kernel(i, j) 
                    End With 
                Next j 
            Next i 
              
            ' Make sure the values are 
            ' between 0 and 255. 
            If r < 0 Then r = 0 
            If r > 255 Then r = 255 
            If g < 0 Then g = 0 
            If g > 255 Then g = 255 
            If b < 0 Then b = 0 
            If b > 255 Then b = 255 
             
            ' Set the output pixel value. 
            With result_pixels(X, Y) 
                .rgbRed = r 
                .rgbGreen = g 
                .rgbBlue = b 
            End With 
        Next X 
    Next Y 

    ' Set picResult's pixels.
    SetBitmapPixels picResult, bits_per_pixel, result_pixels 
    picResult.Picture = picResult.Image 
End Sub

 
< previous page page_193 next page >